import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/31 8:47
 * @description 思路：计数，然后逆序遍历，存在的整数，当个数正好等于 i时输出
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution =  new Solution();
        int[] nums = {3,5};
        solution.specialArray(nums);
    }
    public int specialArray(int[] nums) {
        int[] cnt = new int[1001];
        for (int num : nums) {
            cnt[num]++;
        }
        int sum = 0;
        for (int i = 1000; i >= 1; i--) {
            sum += cnt[i];
            if (sum == i) {
                return i;
            }
        }
        return -1;
    }
}
